package rank;

import org.jboss.netty.buffer.ChannelBuffer;

import util.ChannelBufferUtil;

public class PVPRankNode extends RankNode {
//	public RankPlayer player;	
	private int _ranking;
	
	public String name;
	public String guid;
	public int sex;
	public int level;	
	
	public int pvpScore;
	public int pvpWinPercent;
	
	public PVPRankNode() {
//		this.player = player;
//		player.pvpRankNode = this;
	}
	
	public boolean isGradeNode() {
		return level == Integer.MIN_VALUE;
	}

	@Override
	public int compareTo(RankNode other) {
		PVPRankNode op = (PVPRankNode)other;
//		RankPlayer op = ((PVPRankNode)n).player;
		if (this.pvpScore != op.pvpScore)
			return this.pvpScore>op.pvpScore?1:-1;
		if (this.pvpWinPercent != op.pvpWinPercent) 
			return this.pvpWinPercent>op.pvpWinPercent?1:-1;
		if (this.level != op.level)
			return this.level>op.level?1:-1;
		return 0;
	}

	@Override
	public void setRanking(int ranking) {
		_ranking = ranking;
//		player.pvpRank = ranking - (Config.gradeScore.length - player.pvpLevel) + 1;
	}

	@Override
	public int getRanking() {
		return _ranking;
//		return player.pvpRank;
	}
	
	public void serialize(ChannelBuffer buf) {
		ChannelBufferUtil.writeString(buf, guid);
		buf.writeByte(sex);
		ChannelBufferUtil.writeString(buf, name);
		buf.writeInt(level);
		buf.writeInt(pvpScore);
		buf.writeInt(getRanking());
		buf.writeInt(pvpWinPercent);
	}

}
